package Title;

import java.io.*;
import java.util.ArrayList;

public class Rename_leetcode {
    static class Node {
        String num;
        String name;
        String percent;
        String kind;

        Node(String num, String name, String percent, String kind) {
            this.num = num;
            this.name = name;
            this.percent = percent;
            this.kind = kind;
        }

        public String getNum() {
            return num;
        }

        public String getName() {
            return name;
        }

        public String getPercent() {
            return percent;
        }

        public String getKind() {
            return kind;
        }

        @Override
        public String toString() {
            return "Node{" +
                    "num='" + num + '\'' +
                    ", name='" + name + '\'' +
                    ", percent='" + percent + '\'' +
                    ", kind='" + kind + '\'' +
                    '}';
        }
    }

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new FileReader(new File("D:\\leetcode_probrems.txt")));
        String s;
        ArrayList<String> line = new ArrayList<>();
        while ((s = br.readLine()) != null) {
            line.add(s);
        }
        br.close();

        ArrayList<Node> nodeList = new ArrayList<>();
        for (int i = 0; i < line.size(); i += 2) {
            String num = line.get(i).trim();
            String s1 = line.get(i + 1);

            String s1_1 = s1.substring(0, s1.indexOf("%") - 4).trim().replaceAll("\\s+", "");

            String[] split = s1.split("\\s+");
            String s1_2 = split[split.length - 2];
            String s1_3 = split[split.length - 1];

//            System.out.println(num);
//            System.out.println(s1_1);
//            System.out.println(s1_2);
//            System.out.println(s1_3);

            Node node = new Node(num, s1_1, s1_2, s1_3);
            nodeList.add(node);
        }

        System.out.println(nodeList.toString());

        //使用数据
        ArrayList<String> nameList = new ArrayList<>();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < nodeList.size(); i++) {
            Node node = nodeList.get(i);
            String num = node.getNum();
            String s1 = "000" + num;
            String number = s1.substring(s1.length() - 3, s1.length());


            sb.append(node.getPercent()).append("\t").append(node.getKind()).append("\t").append("LC_").append(number).append("_").append(node.getName());
            nameList.add(sb.toString());
            sb.setLength(0);
        }
        System.out.println(nameList.toString());


        BufferedWriter bw1 = new BufferedWriter(new FileWriter("D:\\leetcode_names.txt"));
        for (int i = 0; i < nameList.size() - 1; i++) {
            bw1.write(nameList.get(i));
            bw1.newLine();
        }
        bw1.write(nameList.get(nameList.size() - 1));
        bw1.close();

    }

}
